package top.wardyan.wtask.tapd.util;

import java.sql.Timestamp;
import java.util.HashMap;

import com.jfinal.kit.Prop;

import cn.hutool.core.lang.Console;
import top.wardyan.base.common.config.ConfigProp;
import top.wardyan.base.common.db.kits.ProcKit;
import top.wardyan.base.common.util.DateUtil;

public class TapdUtil {

	private static final cn.hutool.log.Log log = cn.hutool.log.Log.get();
	private static final Prop PROP = ConfigProp.load();
	
	public static void yp_tapd_clearworkhour(Timestamp date, String man) {
		ProcKit.exec("yp_tapd_clearworkhour", new HashMap<String,Object>(){{
			this.put("pDate", date);
			this.put("pMan", man);
		}});	
	}
	
	public static void yp_tapd_workhour(Timestamp date, String man, String cust, Integer tapdid, Float hour, Boolean isFinish) {

		ProcKit.exec("yp_tapd_workhour", new HashMap<String,Object>(){{
			this.put("pDate", date);
			this.put("pMan", man);
			this.put("pCust", cust);
			this.put("pTapdID", tapdid);
			this.put("pHour", hour);
			this.put("pIsFinish", isFinish);
		}});	
	}
	
	

	/**
	 * 周报开始时间
	 * @param date
	 * @return
	 */
	public static Timestamp getWeekBeginTime(Timestamp date) {
		Timestamp rs = null;
		if(date == null) {
			date = DateUtil.getCurrentTimestamp();
		}
		//
//		Integer weekday = PROP.getInt("feishu.devreport.begindate", 1);
//		String time = PROP.get("feishu.devreport.begintime", "13:00:00");
		
		rs = DateUtil.parse(DateUtil.format(new Timestamp( DateUtil.range(date, 3).getTime() + 1000 * 60 * 60 * 24), "yyyy-MM-dd 13:00:00"));
		
		return rs;
	}
	/**
	 * 周报结束时间
	 * @param date
	 * @return
	 */
	public static Timestamp getWeekEndTime(Timestamp date) {
		Timestamp rs = null;
		if(date == null) {
			date = DateUtil.getCurrentTimestamp();
		}
		//
//		Integer weekday = PROP.getInt("feishu.devreport.begindate", 1);
//		String time = PROP.get("feishu.devreport.begintime", "13:00:00");
		
		rs = DateUtil.parse(DateUtil.format(new Timestamp( DateUtil.range(date, 3).getTime() + 1000 * 60 * 60 * 24 * 8), "yyyy-MM-dd 12:59:59"));
		
		return rs;
	}
	
	
	public static void main(String[] args) {
		Console.log(DateUtil.range(3));
		Console.log(getWeekBeginTime(DateUtil.getCurrentTimestamp()));
		Console.log(getWeekEndTime(DateUtil.getCurrentTimestamp()));
	}
}
